﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.IO;
using System.Runtime.InteropServices;

namespace FWMS
{
    public partial class Form_chukuguanli : Form
    {
        [DllImport("kernel32.dll")]
        public static extern IntPtr _lopen(string lpPathName, int iReadWrite);
        [DllImport("kernel32.dll")]
        public static extern void fclose(IntPtr hObject);
        [DllImport("kernel32.dll")]
        public static extern bool CloseHandle(IntPtr hObject);
        public const int OF_READWRITE = 2;
        public const int OF_SHARE_DENY_NONE = 0x40;
        public readonly IntPtr HFILE_ERROR = new IntPtr(-1);
        //EXCEL明细
        private static string sheet4name = "insert";
        //类型选择
        private static int chukustyle;
        //查询结果的数据
        public object[,] Selectresult;
        //条件查询结果的数据
        public object[,] ConditionSelectresult;
        //出库管理
        public Form_chukuguanli()
        {
            InitializeComponent();
        }
        //出库管理初始化
        private void Form_chukuguanli_Load(object sender, EventArgs e)
        {
            this.chanpin_importexcel_btn.Enabled = false;
            chanpin_importexcel_btn.Visible = false;
            this.toolStrip2.Items.Insert(1, new System.Windows.Forms.ToolStripControlHost(chuku_dtp_select));
            COMMAND.CommandBean.chukuflag = true;
            chukustyle = 0;
            chuku_yuancailiao_init();
        }
        //原材料初始化
        private void chuku_yuancailiao_init()
        {
            //原材料类型为0，调味料1,辅料2,产品3
            chukustyle = 0;//原材料
            Bean.Chukuguanli_yuancailiaoBean bean = new FWMS.Bean.Chukuguanli_yuancailiaoBean();
            Service.Chukuguanli_yuanliaoService service = new FWMS.Service.Chukuguanli_yuanliaoService();
            this.chuku_yuanliao_dtp_yanshou.Value = System.DateTime.Now;
            this.chuku_yuanliao_dgv.Rows.Clear();
            if (this.chuku_yuanliao_dgv.Rows.Count < 30)
            {
                //初始化数据集五行
                for (int i = 0; i < 30; i++)
                {
                    this.chuku_yuanliao_dgv.Rows.Add();
                }
                this.chuku_yuanliao_dtp_yanshou.Value = DateTime.Now;
            }
        }
        //调味料初始化
        private void chuku_tiaoweiliao_init()
        {
            //原材料类型为0，调味料1,辅料2,产品3
            chukustyle = 1;//调味料
            this.chuku_tiaoweiliao_dtp_yanshou.Value = System.DateTime.Now;
            Bean.Chukuguanli_tiaoweiliaoBean bean = new FWMS.Bean.Chukuguanli_tiaoweiliaoBean();
            Service.Chukuguanli_tiaoweiliaoService service = new FWMS.Service.Chukuguanli_tiaoweiliaoService();
            this.chuku_tiaoweiliao_dgv.Rows.Clear();
            if (this.chuku_tiaoweiliao_dgv.Rows.Count < 30)
            {
                //初始化数据集五行
                for (int i = 0; i < 30; i++)
                {
                    this.chuku_tiaoweiliao_dgv.Rows.Add();
                }
                this.chuku_tiaoweiliao_dtp_yanshou.Value = DateTime.Now;
            }
        }
        //辅料初始化
        private void chuku_fuliao_init()
        {
            //原材料类型为0，调味料1,辅料2,产品3
            chukustyle = 2;//调味料
            this.chuku_fuliao_dtp_yanshou.Value = System.DateTime.Now;
            Bean.Chukuguanli_fuliaoBean bean = new FWMS.Bean.Chukuguanli_fuliaoBean();
            Service.Chukuguanli_fuliaoService service = new FWMS.Service.Chukuguanli_fuliaoService();
            //初始化原材料品名
            this.chuku_fuliao_dgv.Rows.Clear();
            if (this.chuku_fuliao_dgv.Rows.Count < 30)
            {
                //初始化数据集五行
                for (int i = 0; i < 30; i++)
                {
                    this.chuku_fuliao_dgv.Rows.Add();
                }
                this.chuku_fuliao_dtp_yanshou.Value = DateTime.Now;

            }

        }
        //产品初始化
        private void chuku_chanpin_init()
        {
            //原材料类型为0，调味料1,辅料2,产品3
            chukustyle = 3;//调味料
            this.chuku_chanpin_dtp_yanshou.Value = System.DateTime.Now;
            Bean.Chukuguanli_chanpinBean bean = new FWMS.Bean.Chukuguanli_chanpinBean();
            Service.Chukuguanli_chanpinService service = new FWMS.Service.Chukuguanli_chanpinService();
            //初始化原材料品名
            this.chuku_chanpin_dgv.Rows.Clear();
            if (this.chuku_chanpin_dgv.Rows.Count < 30)
            {
                //初始化数据集五行
                for (int i = 0; i < 30; i++)
                {
                    this.chuku_chanpin_dgv.Rows.Add();
                }
                this.chuku_chanpin_dtp_yanshou.Value = DateTime.Now;
            }
        }
        //选项卡变换
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            chukustyle = this.tabControl1.SelectedIndex;
            switch (chukustyle)
            {
                case 0: this.chanpin_importexcel_btn.Enabled = false; chanpin_importexcel_btn.Visible = false; chuku_yuancailiao_init(); break;
                case 1: this.chanpin_importexcel_btn.Enabled = false; chanpin_importexcel_btn.Visible = false; chuku_tiaoweiliao_init(); break;
                case 2: this.chanpin_importexcel_btn.Enabled = false; chanpin_importexcel_btn.Visible = false; chuku_fuliao_init(); break;
                case 3: this.chanpin_importexcel_btn.Enabled = true; chanpin_importexcel_btn.Visible = true; chuku_chanpin_init(); break;
                default: break;
            }
        }
        //保存出库数据
        private void chuku_bt_save_Click(object sender, EventArgs e)
        {
            switch (chukustyle)
            {
                case 0: lbl_sum.Visible = false; lbl_sum.Text = "0"; chuku_yuanliao_save(); break;
                case 1: lbl_sum.Visible = false; lbl_sum.Text = "0"; chuku_tiaoweiliao_save(); break;
                case 2: lbl_sum.Visible = false; lbl_sum.Text = "0"; chuku_fuliao_save(); break;
                case 3: lbl_sum.Visible = false; lbl_sum.Text = "0"; chuku_chanpin_save(); break;
                default: break;
            }
        }
        //原料保存数据
        private void chuku_yuanliao_save()
        {
            //原料出库BEAN
            Bean.Chukuguanli_yuancailiaoBean bean = new FWMS.Bean.Chukuguanli_yuancailiaoBean();
            //原料出库SERVICE
            Service.Chukuguanli_yuanliaoService chukuguanli_yuancailiaoService = new FWMS.Service.Chukuguanli_yuanliaoService();
            if (!chuku_infocheck(bean))
            {
                return;
            }
            //入库类型
            bean.Chuku_type = chukustyle.ToString();
            //原料基本信息CHECK
            int numcont = this.chuku_yuanliao_dgv.Rows.Count;
            Selectresult = new object[numcont, 8];
            int j;
            int i = 0;
            for (j = 0; j < numcont; j++)
            {
                //获取品名
                if (this.chuku_yuanliao_dgv.Rows[j].Cells[0].Value == null)
                {
                    continue;
                }
                else
                {
                    if ("".Equals(this.chuku_yuanliao_dgv.Rows[j].Cells[0].Value.ToString().Trim()))
                    {
                        continue;
                    }
                    else
                    {
                        Selectresult[j, 0] = this.chuku_yuanliao_dgv.Rows[j].Cells[0].Value.ToString().Trim();
                        i++;
                    }
                }
                //获取规格
                if (this.chuku_yuanliao_dgv.Rows[j].Cells[1].Value == null)
                {
                    Selectresult[j, 1] = "";
                }
                else
                {
                    Selectresult[j, 1] = this.chuku_yuanliao_dgv.Rows[j].Cells[1].Value.ToString().Trim();
                }
                //获取单位
                if (this.chuku_yuanliao_dgv.Rows[j].Cells[2].Value == null)
                {
                    Selectresult[j, 2] = "";
                }
                else
                {
                    Selectresult[j, 2] = this.chuku_yuanliao_dgv.Rows[j].Cells[2].Value.ToString().Trim();
                }
                //获取单价
                if (this.chuku_yuanliao_dgv.Rows[j].Cells[3].Value == null)
                {
                    Selectresult[j, 3] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_yuanliao_dgv.Rows[j].Cells[3].Value))
                    {
                        Selectresult[j, 3] = 0;
                    }
                    else
                    {
                        Selectresult[j, 3] = this.chuku_yuanliao_dgv.Rows[j].Cells[3].Value.ToString().Trim();
                    }
                }
                //获取件数
                if (this.chuku_yuanliao_dgv.Rows[j].Cells[4].Value == null)
                {
                    Selectresult[j, 4] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_yuanliao_dgv.Rows[j].Cells[4].Value))
                    {
                        Selectresult[j, 4] = 0;
                    }
                    else
                    {
                        Selectresult[j, 4] = this.chuku_yuanliao_dgv.Rows[j].Cells[4].Value.ToString().Trim();
                    }

                }
                //获取重量
                if (this.chuku_yuanliao_dgv.Rows[j].Cells[5].Value == null)
                {
                    Selectresult[j, 5] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_yuanliao_dgv.Rows[j].Cells[5].Value))
                    {
                        Selectresult[j, 5] = 0;
                    }
                    else
                    {
                        Selectresult[j, 5] = this.chuku_yuanliao_dgv.Rows[j].Cells[5].Value.ToString().Trim();
                    }

                }
                //获取总值
                if (this.chuku_yuanliao_dgv.Rows[j].Cells[6].Value == null)
                {
                    Selectresult[j, 6] = "";
                }
                else
                {
                    Selectresult[j, 6] = this.chuku_yuanliao_dgv.Rows[j].Cells[6].Value.ToString().Trim();
                }
                //获取备注
                if (this.chuku_yuanliao_dgv.Rows[j].Cells[7].Value == null)
                {
                    Selectresult[j, 7] = "";
                }
                else
                {
                    Selectresult[j, 7] = this.chuku_yuanliao_dgv.Rows[j].Cells[7].Value.ToString().Trim();
                }
            }
            if (i == 0)
            {
                MessageBox.Show("当前无保存数据！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                i = 0;
            }
            //数据集接收完毕
            bean.Selectresult = Selectresult;
            bean.Resultrow = i;
            if (!chukuguanli_yuancailiaoService.chukuguanli_yuancailiaoServiceAdd(bean))
            {
                MessageBox.Show("数据保存失败，请重新保存！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Bean.Chukuguanli_yuancailiaoBean yuanliaokucunbean = new FWMS.Bean.Chukuguanli_yuancailiaoBean();
                Service.Chukuguanli_yuanliaoService service = new FWMS.Service.Chukuguanli_yuanliaoService();
                yuanliaokucunbean.Chuku_yanshou = this.chuku_yuanliao_dtp_yanshou.Value.ToString("yyyyMMdd");
                yuanliaokucunbean = service.chukuguanli_yuancailiao_kucunguanliServiceSelectContation(yuanliaokucunbean);
                service.chukuguanli_yuancailiaokucundatechulijian(yuanliaokucunbean);
                MessageBox.Show("数据保存成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        //调味料保存数据
        private void chuku_tiaoweiliao_save()
        {
            //if (!comsavedate(this.chuku_tiaoweiliao_dtp_yanshou.Value.ToString("yyyyMMdd"), chukustyle.ToString().Trim()))
            //{
            //    return;
            //}
            Bean.Chukuguanli_tiaoweiliaoBean bean = new FWMS.Bean.Chukuguanli_tiaoweiliaoBean();
            Service.Chukuguanli_tiaoweiliaoService chukuguanli_tialweiliaoService = new FWMS.Service.Chukuguanli_tiaoweiliaoService();
            if (!chuku_infocheck(bean))
            {
                return;
            }
            //入库类型
            bean.Chuku_type = chukustyle.ToString();
            //原料基本信息CHECK
            int numcont = this.chuku_tiaoweiliao_dgv.Rows.Count;
            Selectresult = new object[numcont, 8];
            int j;
            int i = 0;
            for (j = 0; j < numcont; j++)
            {
                //获取品名
                if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[0].Value == null)
                {
                    continue;
                }
                else
                {
                    if ("".Equals(this.chuku_tiaoweiliao_dgv.Rows[j].Cells[0].Value.ToString().Trim()))
                    {
                        continue;
                    }
                    else
                    {
                        Selectresult[j, 0] = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[0].Value.ToString().Trim();

                        i++;
                    }
                }
                //获取规格
                if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[1].Value == null)
                {
                    Selectresult[j, 1] = "";
                }
                else
                {
                    Selectresult[j, 1] = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[1].Value.ToString().Trim();
                }
                //获取单位
                if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[2].Value == null)
                {
                    Selectresult[j, 2] = "";
                }
                else
                {
                    Selectresult[j, 2] = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[2].Value.ToString().Trim();
                }
                //获取单价
                if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[3].Value == null)
                {
                    Selectresult[j, 3] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_tiaoweiliao_dgv.Rows[j].Cells[3].Value))
                    {
                        Selectresult[j, 3] = 0;
                    }
                    else
                    {
                        Selectresult[j, 3] = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[3].Value.ToString().Trim();
                    }
                }
                //获取件数
                if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[4].Value == null)
                {
                    Selectresult[j, 4] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_tiaoweiliao_dgv.Rows[j].Cells[4].Value))
                    {
                        Selectresult[j, 4] = 0;
                    }
                    else
                    {
                        Selectresult[j, 4] = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[4].Value.ToString().Trim();
                    }

                }
                //获取重量
                if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[5].Value == null)
                {
                    Selectresult[j, 5] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_tiaoweiliao_dgv.Rows[j].Cells[5].Value))
                    {
                        Selectresult[j, 5] = 0;
                    }
                    else
                    {
                        Selectresult[j, 5] = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[5].Value.ToString().Trim();
                    }

                }
                //获取总值
                if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[6].Value == null)
                {
                    Selectresult[j, 6] = "";
                }
                else
                {
                    Selectresult[j, 6] = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[6].Value.ToString().Trim();
                }
                //获取备注
                if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[7].Value == null)
                {
                    Selectresult[j, 7] = "";
                }
                else
                {
                    Selectresult[j, 7] = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[7].Value.ToString().Trim();
                }
            }
            if (i == 0)
            {
                MessageBox.Show("当前无保存数据！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                i = 0;
            }
            //数据集接收完毕
            bean.Selectresult = Selectresult;
            bean.Resultrow = i;
            if (!chukuguanli_tialweiliaoService.chukuguanli_tiaoweiliaoServiceAdd(bean))
            {
                MessageBox.Show("数据保存失败，请重新保存！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Bean.Chukuguanli_tiaoweiliaoBean tiaoweiliaokucunbean = new FWMS.Bean.Chukuguanli_tiaoweiliaoBean();
                Service.Chukuguanli_tiaoweiliaoService service = new FWMS.Service.Chukuguanli_tiaoweiliaoService();
                tiaoweiliaokucunbean.Chuku_yanshou = this.chuku_tiaoweiliao_dtp_yanshou.Value.ToString("yyyyMMdd");
                tiaoweiliaokucunbean = service.chukuguanli_tiaoweiliao_kucunguanliServiceSelectContation(tiaoweiliaokucunbean);
                service.chukuguanli_tiaoweiliaokucundatechulijian(tiaoweiliaokucunbean);
                MessageBox.Show("数据保存成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        //辅料保存数据
        private void chuku_fuliao_save()
        {
            //if (!comsavedate(this.chuku_fuliao_dtp_yanshou.Value.ToString("yyyyMMdd"), chukustyle.ToString().Trim()))
            //{
            //    return;
            //}
            Bean.Chukuguanli_fuliaoBean bean = new FWMS.Bean.Chukuguanli_fuliaoBean();
            Service.Chukuguanli_fuliaoService chukuguanli_fuliaoService = new FWMS.Service.Chukuguanli_fuliaoService();
            if (!chuku_infocheck(bean))
            {
                return;
            }
            //入库类型
            bean.Chuku_type = chukustyle.ToString();
            //原料基本信息CHECK
            int numcont = this.chuku_fuliao_dgv.Rows.Count;
            Selectresult = new object[numcont, 8];
            int j;
            int i = 0;
            for (j = 0; j < numcont; j++)
            {
                //获取品名
                if (this.chuku_fuliao_dgv.Rows[j].Cells[0].Value == null)
                {
                    continue;
                }
                else
                {
                    if ("".Equals(this.chuku_fuliao_dgv.Rows[j].Cells[0].Value.ToString().Trim()))
                    {
                        continue;
                    }
                    else
                    {
                        Selectresult[j, 0] = this.chuku_fuliao_dgv.Rows[j].Cells[0].Value.ToString().Trim();

                        i++;
                    }
                }
                //获取规格
                if (this.chuku_fuliao_dgv.Rows[j].Cells[1].Value == null)
                {
                    Selectresult[j, 1] = "";
                }
                else
                {
                    Selectresult[j, 1] = this.chuku_fuliao_dgv.Rows[j].Cells[1].Value.ToString().Trim();
                }
                //获取单位
                if (this.chuku_fuliao_dgv.Rows[j].Cells[2].Value == null)
                {
                    Selectresult[j, 2] = "";
                }
                else
                {
                    Selectresult[j, 2] = this.chuku_fuliao_dgv.Rows[j].Cells[2].Value.ToString().Trim();
                }
                //获取单价
                if (this.chuku_fuliao_dgv.Rows[j].Cells[3].Value == null)
                {
                    Selectresult[j, 3] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_fuliao_dgv.Rows[j].Cells[3].Value))
                    {
                        Selectresult[j, 3] = 0;
                    }
                    else
                    {
                        Selectresult[j, 3] = this.chuku_fuliao_dgv.Rows[j].Cells[3].Value.ToString().Trim();
                    }
                }
                //获取件数
                if (this.chuku_fuliao_dgv.Rows[j].Cells[4].Value == null)
                {
                    Selectresult[j, 4] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_fuliao_dgv.Rows[j].Cells[4].Value))
                    {
                        Selectresult[j, 4] = 0;
                    }
                    else
                    {
                        Selectresult[j, 4] = this.chuku_fuliao_dgv.Rows[j].Cells[4].Value.ToString().Trim();
                    }

                }
                //获取重量
                if (this.chuku_fuliao_dgv.Rows[j].Cells[5].Value == null)
                {
                    Selectresult[j, 5] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_fuliao_dgv.Rows[j].Cells[5].Value))
                    {
                        Selectresult[j, 5] = 0;
                    }
                    else
                    {
                        Selectresult[j, 5] = this.chuku_fuliao_dgv.Rows[j].Cells[5].Value.ToString().Trim();
                    }

                }
                //获取总值
                if (this.chuku_fuliao_dgv.Rows[j].Cells[6].Value == null)
                {
                    Selectresult[j, 6] = "";
                }
                else
                {
                    Selectresult[j, 6] = this.chuku_fuliao_dgv.Rows[j].Cells[6].Value.ToString().Trim();
                }
                //获取备注
                if (this.chuku_fuliao_dgv.Rows[j].Cells[7].Value == null)
                {
                    Selectresult[j, 7] = "";
                }
                else
                {
                    Selectresult[j, 7] = this.chuku_fuliao_dgv.Rows[j].Cells[7].Value.ToString().Trim();
                }
            }
            if (i == 0)
            {
                MessageBox.Show("当前无保存数据！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                i = 0;
            }
            //数据集接收完毕
            bean.Selectresult = Selectresult;
            bean.Resultrow = i;
            if (!chukuguanli_fuliaoService.chukuguanli_fuliaoServiceAdd(bean))
            {
                MessageBox.Show("数据保存失败，请重新保存！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Bean.Chukuguanli_fuliaoBean fuliaokucunbean = new FWMS.Bean.Chukuguanli_fuliaoBean();
                Service.Chukuguanli_fuliaoService service = new FWMS.Service.Chukuguanli_fuliaoService();
                fuliaokucunbean.Chuku_yanshou = this.chuku_fuliao_dtp_yanshou.Value.ToString("yyyyMMdd");
                fuliaokucunbean = service.chukuguanli_fuliao_kucunguanliServiceSelectContation(fuliaokucunbean);
                service.chukuguanli_fuliaokucundatechulijian(fuliaokucunbean);
                MessageBox.Show("数据保存成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        //成品保存数据
        private void chuku_chanpin_save()
        {
            //if (!comsavedate(this.chuku_chanpin_dtp_yanshou.Value.ToString("yyyyMMdd"), chukustyle.ToString().Trim()))
            //{
            //    return;
            //}
            Bean.Chukuguanli_chanpinBean bean = new FWMS.Bean.Chukuguanli_chanpinBean();
            Service.Chukuguanli_chanpinService chukuguanli_chanpinService = new FWMS.Service.Chukuguanli_chanpinService();
            if (!chuku_infocheck(bean))
            {
                return;
            }
            //入库类型
            bean.Chuku_type = chukustyle.ToString();
            //原料基本信息CHECK
            int numcont = this.chuku_chanpin_dgv.Rows.Count;
            Selectresult = new object[numcont, 8];
            int j;
            int i = 0;
            for (j = 0; j < numcont; j++)
            {
                //获取品名
                if (this.chuku_chanpin_dgv.Rows[j].Cells[0].Value == null)
                {
                    continue;
                }
                else
                {
                    if ("".Equals(this.chuku_chanpin_dgv.Rows[j].Cells[0].Value.ToString().Trim()))
                    {
                        continue;
                    }
                    else
                    {
                        Selectresult[j, 0] = this.chuku_chanpin_dgv.Rows[j].Cells[0].Value.ToString().Trim();

                        i++;
                    }
                }
                //获取规格
                if (this.chuku_chanpin_dgv.Rows[j].Cells[1].Value == null)
                {
                    Selectresult[j, 1] = "";
                }
                else
                {
                    Selectresult[j, 1] = this.chuku_chanpin_dgv.Rows[j].Cells[1].Value.ToString().Trim();
                }
                //获取单位
                if (this.chuku_chanpin_dgv.Rows[j].Cells[2].Value == null)
                {
                    Selectresult[j, 2] = "";
                }
                else
                {
                    Selectresult[j, 2] = this.chuku_chanpin_dgv.Rows[j].Cells[2].Value.ToString().Trim();
                }
                //获取单价
                if (this.chuku_chanpin_dgv.Rows[j].Cells[3].Value == null)
                {
                    Selectresult[j, 3] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_chanpin_dgv.Rows[j].Cells[3].Value))
                    {
                        Selectresult[j, 3] = 0;
                    }
                    else
                    {
                        Selectresult[j, 3] = this.chuku_chanpin_dgv.Rows[j].Cells[3].Value.ToString().Trim();
                    }
                }
                //获取件数
                if (this.chuku_chanpin_dgv.Rows[j].Cells[4].Value == null)
                {
                    Selectresult[j, 4] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_chanpin_dgv.Rows[j].Cells[4].Value))
                    {
                        Selectresult[j, 4] = 0;
                    }
                    else
                    {
                        Selectresult[j, 4] = this.chuku_chanpin_dgv.Rows[j].Cells[4].Value.ToString().Trim();
                    }

                }
                //获取重量
                if (this.chuku_chanpin_dgv.Rows[j].Cells[5].Value == null)
                {
                    Selectresult[j, 5] = 0;
                }
                else
                {
                    if ("".Equals(this.chuku_chanpin_dgv.Rows[j].Cells[5].Value))
                    {
                        Selectresult[j, 5] = 0;
                    }
                    else
                    {
                        Selectresult[j, 5] = this.chuku_chanpin_dgv.Rows[j].Cells[5].Value.ToString().Trim();
                    }

                }
                //获取总值
                if (this.chuku_chanpin_dgv.Rows[j].Cells[6].Value == null)
                {
                    Selectresult[j, 6] = "";
                }
                else
                {
                    Selectresult[j, 6] = this.chuku_chanpin_dgv.Rows[j].Cells[6].Value.ToString().Trim();
                }
                //获取备注
                if (this.chuku_chanpin_dgv.Rows[j].Cells[7].Value == null)
                {
                    Selectresult[j, 7] = "";
                }
                else
                {
                    Selectresult[j, 7] = this.chuku_chanpin_dgv.Rows[j].Cells[7].Value.ToString().Trim();
                }
            }
            if (i == 0)
            {
                MessageBox.Show("当前无保存数据！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                i = 0;
            }
            //数据集接收完毕
            bean.Selectresult = Selectresult;
            bean.Resultrow = i;
            if (!chukuguanli_chanpinService.chukuguanli_chanpinServiceAdd(bean))
            {
                MessageBox.Show("数据保存失败，请重新保存！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Bean.Chukuguanli_chanpinBean chanpinkucunbean = new FWMS.Bean.Chukuguanli_chanpinBean();
                Service.Chukuguanli_chanpinService service = new FWMS.Service.Chukuguanli_chanpinService();
                chanpinkucunbean.Chuku_yanshou = this.chuku_chanpin_dtp_yanshou.Value.ToString("yyyyMMdd");
                chanpinkucunbean = service.chukuguanli_chanpin_kucunguanliServiceSelectContation(chanpinkucunbean);

                service.chukuguanli_chanpinkucundatechulijian(chanpinkucunbean);
                MessageBox.Show("数据保存成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        //出库基本数据CHECK
        private bool chuku_infocheck(object bean)
        {
            switch (chukustyle)
            {
                case 0:
                    Bean.Chukuguanli_yuancailiaoBean yuancailiaobean = (Bean.Chukuguanli_yuancailiaoBean)bean;
                    //验收日期
                    yuancailiaobean.Chuku_yanshou = this.chuku_yuanliao_dtp_yanshou.Value.ToString("yyyyMMdd");
                    //出库基本信息必须全部添写
                    if ("".Equals(yuancailiaobean.Chuku_yanshou))
                    {
                        MessageBox.Show("出库通知单基本信息必须全部添写！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    for (int j = 0; j < this.chuku_yuanliao_dgv.Rows.Count; j++)
                    {
                        //获取品名
                        if (this.chuku_yuanliao_dgv.Rows[j].Cells[0].Value == null)
                        {
                            continue;
                        }
                        //单重输入格式验证
                        if (this.chuku_yuanliao_dgv.Rows[j].Cells[3].Value != null && !"".Equals(this.chuku_yuanliao_dgv.Rows[j].Cells[3].Value.ToString().Trim()))
                        {
                            string danzhong = this.chuku_yuanliao_dgv.Rows[j].Cells[3].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(danzhong);
                            if (!m.Success)
                            {
                                this.chuku_yuanliao_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("单价只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }

                        //重量输入格式验证
                        if (this.chuku_yuanliao_dgv.Rows[j].Cells[5].Value != null && !"".Equals(this.chuku_yuanliao_dgv.Rows[j].Cells[5].Value.ToString().Trim()))
                        {
                            string zhongliang = this.chuku_yuanliao_dgv.Rows[j].Cells[5].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(zhongliang);
                            if (!m.Success)
                            {
                                this.chuku_yuanliao_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("重量只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        //件数输入格式验证
                        if (this.chuku_yuanliao_dgv.Rows[j].Cells[4].Value != null && !"".Equals(this.chuku_yuanliao_dgv.Rows[j].Cells[4].Value.ToString().Trim()))
                        {
                            string jianshu = this.chuku_yuanliao_dgv.Rows[j].Cells[4].Value.ToString().Trim();
                            Regex reg = new Regex("^([-]{1})?[0-9]");
                            Match m = reg.Match(jianshu);
                            if (!m.Success)
                            {
                                this.chuku_yuanliao_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("件数输入只能输入整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        if (!pinming_same_check(this.chuku_yuanliao_dgv.Rows[j].Cells[0].Value.ToString().Trim(), j))
                        {
                            MessageBox.Show("品名,规格和备注录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    Bean.Chukuguanli_yuancailiaoBean kucunbean = new FWMS.Bean.Chukuguanli_yuancailiaoBean();
                    Service.Chukuguanli_yuanliaoService chuku_yuancailiaoService = new FWMS.Service.Chukuguanli_yuanliaoService();
                    kucunbean.Chuku_yanshou = this.chuku_yuanliao_dtp_yanshou.Value.ToString("yyyyMMdd");
                    kucunbean = chuku_yuancailiaoService.chukuguanli_yuancailiao_kucunguanliServiceSelectContation(kucunbean);
                    if (kucunbean.Selectresult != null)
                    {
                        if (MessageBox.Show("输入日期对应己存在数据是否覆盖？", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            chuku_yuancailiaoService.chukuguanli_yuancailiaokucundatechuliadd(kucunbean);
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    return true;
                case 1:
                    Bean.Chukuguanli_tiaoweiliaoBean tiaoweiliaobean = (Bean.Chukuguanli_tiaoweiliaoBean)bean;
                    //验收日期
                    tiaoweiliaobean.Chuku_yanshou = this.chuku_tiaoweiliao_dtp_yanshou.Value.ToString("yyyyMMdd");
                    //出库基本信息必须全部添写
                    if ("".Equals(tiaoweiliaobean.Chuku_yanshou))
                    {
                        MessageBox.Show("出库通知单基本信息必须全部添写！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    for (int j = 0; j < this.chuku_tiaoweiliao_dgv.Rows.Count; j++)
                    {
                        //获取品名
                        if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[0].Value == null)
                        {
                            continue;
                        }
                        //单重输入格式验证
                        if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[3].Value != null && !"".Equals(this.chuku_tiaoweiliao_dgv.Rows[j].Cells[3].Value.ToString().Trim()))
                        {
                            string danzhong = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[3].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(danzhong);
                            if (!m.Success)
                            {
                                this.chuku_tiaoweiliao_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("单价只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }

                        //重量输入格式验证
                        if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[5].Value != null && !"".Equals(this.chuku_tiaoweiliao_dgv.Rows[j].Cells[5].Value.ToString().Trim()))
                        {
                            string zhongliang = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[5].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(zhongliang);
                            if (!m.Success)
                            {
                                this.chuku_tiaoweiliao_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("重量只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        //件数输入格式验证
                        if (this.chuku_tiaoweiliao_dgv.Rows[j].Cells[4].Value != null && !"".Equals(this.chuku_tiaoweiliao_dgv.Rows[j].Cells[4].Value.ToString().Trim()))
                        {
                            string jianshu = this.chuku_tiaoweiliao_dgv.Rows[j].Cells[4].Value.ToString().Trim();
                            Regex reg = new Regex("^([-]{1})?[0-9]");
                            Match m = reg.Match(jianshu);
                            if (!m.Success)
                            {
                                this.chuku_tiaoweiliao_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("件数输入只能输入整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        if (!pinming_same_check(this.chuku_tiaoweiliao_dgv.Rows[j].Cells[0].Value.ToString().Trim(), j))
                        {
                            MessageBox.Show("品名,规格和备注录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    Bean.Chukuguanli_tiaoweiliaoBean tiaoweiliaokucunbean = new FWMS.Bean.Chukuguanli_tiaoweiliaoBean();
                    Service.Chukuguanli_tiaoweiliaoService chuku_tiaoweiliaoService = new FWMS.Service.Chukuguanli_tiaoweiliaoService();
                    tiaoweiliaokucunbean.Chuku_yanshou = this.chuku_tiaoweiliao_dtp_yanshou.Value.ToString("yyyyMMdd");
                    tiaoweiliaokucunbean = chuku_tiaoweiliaoService.chukuguanli_tiaoweiliao_kucunguanliServiceSelectContation(tiaoweiliaokucunbean);
                    if (tiaoweiliaokucunbean.Selectresult != null)
                    {
                        if (MessageBox.Show("输入日期对应己存在数据是否覆盖？", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            chuku_tiaoweiliaoService.chukuguanli_tiaoweiliaokucundatechuliadd(tiaoweiliaokucunbean);
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    return true;
                case 2:
                    Bean.Chukuguanli_fuliaoBean fuliaobean = (Bean.Chukuguanli_fuliaoBean)bean;
                    //验收日期
                    fuliaobean.Chuku_yanshou = this.chuku_fuliao_dtp_yanshou.Value.ToString("yyyyMMdd");
                    //出库基本信息必须全部添写
                    if ("".Equals(fuliaobean.Chuku_yanshou))
                    {
                        MessageBox.Show("出库通知单基本信息必须全部添写！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    for (int j = 0; j < this.chuku_fuliao_dgv.Rows.Count; j++)
                    {
                        //获取品名
                        if (this.chuku_fuliao_dgv.Rows[j].Cells[0].Value == null)
                        {
                            continue;
                        }
                        //单重输入格式验证
                        if (this.chuku_fuliao_dgv.Rows[j].Cells[3].Value != null && !"".Equals(this.chuku_fuliao_dgv.Rows[j].Cells[3].Value.ToString().Trim()))
                        {
                            string danzhong = this.chuku_fuliao_dgv.Rows[j].Cells[3].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(danzhong);
                            if (!m.Success)
                            {
                                this.chuku_fuliao_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("单价只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }

                        //重量输入格式验证
                        if (this.chuku_fuliao_dgv.Rows[j].Cells[5].Value != null && !"".Equals(this.chuku_fuliao_dgv.Rows[j].Cells[5].Value.ToString().Trim()))
                        {
                            string zhongliang = this.chuku_fuliao_dgv.Rows[j].Cells[5].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(zhongliang);
                            if (!m.Success)
                            {
                                this.chuku_fuliao_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("重量只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        //件数输入格式验证
                        if (this.chuku_fuliao_dgv.Rows[j].Cells[4].Value != null && !"".Equals(this.chuku_fuliao_dgv.Rows[j].Cells[4].Value.ToString().Trim()))
                        {
                            string jianshu = this.chuku_fuliao_dgv.Rows[j].Cells[4].Value.ToString().Trim();
                            Regex reg = new Regex("^([-]{1})?[0-9]");
                            Match m = reg.Match(jianshu);
                            if (!m.Success)
                            {
                                this.chuku_fuliao_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("件数输入只能输入整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        if (!pinming_same_check(this.chuku_fuliao_dgv.Rows[j].Cells[0].Value.ToString().Trim(), j))
                        {
                            MessageBox.Show("品名,规格和备注录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    Bean.Chukuguanli_fuliaoBean fuliaokucunbean = new FWMS.Bean.Chukuguanli_fuliaoBean();
                    Service.Chukuguanli_fuliaoService chuku_fuliaoService = new FWMS.Service.Chukuguanli_fuliaoService();
                    fuliaokucunbean.Chuku_yanshou = this.chuku_fuliao_dtp_yanshou.Value.ToString("yyyyMMdd");
                    fuliaokucunbean = chuku_fuliaoService.chukuguanli_fuliao_kucunguanliServiceSelectContation(fuliaokucunbean);
                    if (fuliaokucunbean.Selectresult != null)
                    {
                        if (MessageBox.Show("输入日期对应己存在数据是否覆盖？", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            chuku_fuliaoService.chukuguanli_fuliaokucundatechuliadd(fuliaokucunbean);
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    return true;
                case 3:
                    Bean.Chukuguanli_chanpinBean chanpinbean = (Bean.Chukuguanli_chanpinBean)bean;
                    //验收日期
                    chanpinbean.Chuku_yanshou = this.chuku_chanpin_dtp_yanshou.Value.ToString("yyyyMMdd");
                    //出库基本信息必须全部添写
                    if ("".Equals(chanpinbean.Chuku_yanshou))
                    {
                        MessageBox.Show("出库通知单基本信息必须全部添写！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    for (int j = 0; j < this.chuku_chanpin_dgv.Rows.Count; j++)
                    {
                        //获取品名
                        if (this.chuku_chanpin_dgv.Rows[j].Cells[0].Value == null)
                        {
                            continue;
                        }
                        //单重输入格式验证
                        if (this.chuku_chanpin_dgv.Rows[j].Cells[3].Value != null && !"".Equals(this.chuku_chanpin_dgv.Rows[j].Cells[3].Value.ToString().Trim()))
                        {
                            string danzhong = this.chuku_chanpin_dgv.Rows[j].Cells[3].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(danzhong);
                            if (!m.Success)
                            {
                                this.chuku_chanpin_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("单价只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }

                        //重量输入格式验证
                        if (this.chuku_chanpin_dgv.Rows[j].Cells[5].Value != null && !"".Equals(this.chuku_chanpin_dgv.Rows[j].Cells[5].Value.ToString().Trim()))
                        {
                            string zhongliang = this.chuku_chanpin_dgv.Rows[j].Cells[5].Value.ToString().Trim();
                            Regex reg = new Regex("^(-?[0-9])+(.[0-9]{1,3})?$");
                            Match m = reg.Match(zhongliang);
                            if (!m.Success)
                            {
                                this.chuku_chanpin_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("重量只能输入小数位数最大为三位的数值！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        //件数输入格式验证
                        if (this.chuku_chanpin_dgv.Rows[j].Cells[4].Value != null && !"".Equals(this.chuku_chanpin_dgv.Rows[j].Cells[4].Value.ToString().Trim()))
                        {
                            string jianshu = this.chuku_chanpin_dgv.Rows[j].Cells[4].Value.ToString().Trim();
                            Regex reg = new Regex("^([-]{1})?[0-9]");
                            Match m = reg.Match(jianshu);
                            if (!m.Success)
                            {
                                this.chuku_chanpin_dgv.Rows[j].DefaultCellStyle.BackColor = System.Drawing.Color.LightPink;
                                MessageBox.Show("件数输入只能输入整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return false;
                            }
                        }
                        /*
                        if (!pinming_same_check(this.chuku_chanpin_dgv.Rows[j].Cells[0].Value.ToString().Trim(), j))
                        {
                            MessageBox.Show("品名,规格和合同号录入重复", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }*/
                    }
                    Bean.Chukuguanli_chanpinBean chanpinkucunbean = new FWMS.Bean.Chukuguanli_chanpinBean();
                    Service.Chukuguanli_chanpinService chuku_chanpinService = new FWMS.Service.Chukuguanli_chanpinService();
                    chanpinkucunbean.Chuku_yanshou = this.chuku_chanpin_dtp_yanshou.Value.ToString("yyyyMMdd");
                    chanpinkucunbean = chuku_chanpinService.chukuguanli_chanpin_kucunguanliServiceSelectContation(chanpinkucunbean);
                    if (chanpinkucunbean.Selectresult != null)
                    {
                        if (MessageBox.Show("输入日期对应己存在数据是否覆盖？", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            chuku_chanpinService.chukuguanli_chanpinkucundatechuliadd(chanpinkucunbean);
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    return true;
                default: return true;
            }

        }
        //品名相同CHECK
        private bool pinming_same_check(string pinming, int nowsite)
        {

            switch (chukustyle)
            {
                case 0:
                    for (int i = nowsite + 1; i < this.chuku_yuanliao_dgv.Rows.Count; i++)
                    {
                        if (this.chuku_yuanliao_dgv.Rows[i].Cells[0].Value == null)
                        {
                            continue;
                        }
                        else
                        {
                            if (pinming.Equals(this.chuku_yuanliao_dgv.Rows[i].Cells[0].Value.ToString().Trim()))
                            {
                                if (this.chuku_yuanliao_dgv.Rows[nowsite].Cells[1].Value == null)
                                {
                                    this.chuku_yuanliao_dgv.Rows[nowsite].Cells[1].Value = "";
                                }
                                if (this.chuku_yuanliao_dgv.Rows[i].Cells[1].Value == null)
                                {
                                    this.chuku_yuanliao_dgv.Rows[i].Cells[1].Value = "";
                                }
                                if (this.chuku_yuanliao_dgv.Rows[nowsite].Cells[1].Value.ToString().Trim().Equals(this.chuku_yuanliao_dgv.Rows[i].Cells[1].Value.ToString().Trim()))
                                {
                                    if (this.chuku_yuanliao_dgv.Rows[nowsite].Cells[7].Value == null)
                                    {
                                        this.chuku_yuanliao_dgv.Rows[nowsite].Cells[7].Value = "";
                                    }
                                    if (this.chuku_yuanliao_dgv.Rows[i].Cells[7].Value == null)
                                    {
                                        this.chuku_yuanliao_dgv.Rows[i].Cells[7].Value = "";
                                    }
                                    if (this.chuku_yuanliao_dgv.Rows[nowsite].Cells[7].Value.ToString().Trim().Equals(this.chuku_yuanliao_dgv.Rows[i].Cells[7].Value.ToString().Trim()))
                                    {
                                        return false;
                                    }
                                }
                            }
                        }

                    }
                    return true;
                case 1:
                    for (int i = nowsite + 1; i < this.chuku_tiaoweiliao_dgv.Rows.Count; i++)
                    {
                        if (this.chuku_tiaoweiliao_dgv.Rows[i].Cells[0].Value == null)
                        {
                            continue;
                        }
                        else
                        {

                            if (pinming.Equals(this.chuku_tiaoweiliao_dgv.Rows[i].Cells[0].Value.ToString().Trim()))
                            {
                                if (this.chuku_tiaoweiliao_dgv.Rows[nowsite].Cells[1].Value == null)
                                {
                                    this.chuku_tiaoweiliao_dgv.Rows[nowsite].Cells[1].Value = "";
                                }
                                if (this.chuku_tiaoweiliao_dgv.Rows[i].Cells[1].Value == null)
                                {
                                    this.chuku_tiaoweiliao_dgv.Rows[i].Cells[1].Value = "";
                                }
                                if (this.chuku_tiaoweiliao_dgv.Rows[nowsite].Cells[1].Value.ToString().Trim().Equals(this.chuku_tiaoweiliao_dgv.Rows[i].Cells[1].Value.ToString().Trim()))
                                {
                                    if (this.chuku_tiaoweiliao_dgv.Rows[nowsite].Cells[7].Value == null)
                                    {
                                        this.chuku_tiaoweiliao_dgv.Rows[nowsite].Cells[7].Value = "";
                                    }
                                    if (this.chuku_tiaoweiliao_dgv.Rows[i].Cells[7].Value == null)
                                    {
                                        this.chuku_tiaoweiliao_dgv.Rows[i].Cells[7].Value = "";
                                    }
                                    if (this.chuku_tiaoweiliao_dgv.Rows[nowsite].Cells[7].Value.ToString().Trim().Equals(this.chuku_tiaoweiliao_dgv.Rows[i].Cells[7].Value.ToString().Trim()))
                                    {
                                        return false;
                                    }
                                }
                            }
                        }

                    }
                    return true;
                case 2:
                    for (int i = nowsite + 1; i < this.chuku_fuliao_dgv.Rows.Count; i++)
                    {
                        if (this.chuku_fuliao_dgv.Rows[i].Cells[0].Value == null)
                        {
                            continue;
                        }
                        else
                        {

                            if (pinming.Equals(this.chuku_fuliao_dgv.Rows[i].Cells[0].Value.ToString().Trim()))
                            {
                                if (this.chuku_fuliao_dgv.Rows[nowsite].Cells[1].Value == null)
                                {
                                    this.chuku_fuliao_dgv.Rows[nowsite].Cells[1].Value = "";
                                }
                                if (this.chuku_fuliao_dgv.Rows[i].Cells[1].Value == null)
                                {
                                    this.chuku_fuliao_dgv.Rows[i].Cells[1].Value = "";
                                }
                                if (this.chuku_fuliao_dgv.Rows[nowsite].Cells[1].Value.ToString().Trim().Equals(this.chuku_fuliao_dgv.Rows[i].Cells[1].Value.ToString().Trim()))
                                {
                                    if (this.chuku_fuliao_dgv.Rows[nowsite].Cells[7].Value == null)
                                    {
                                        this.chuku_fuliao_dgv.Rows[nowsite].Cells[7].Value = "";
                                    }
                                    if (this.chuku_fuliao_dgv.Rows[i].Cells[7].Value == null)
                                    {
                                        this.chuku_fuliao_dgv.Rows[i].Cells[7].Value = "";
                                    }
                                    if (this.chuku_fuliao_dgv.Rows[nowsite].Cells[7].Value.ToString().Trim().Equals(this.chuku_fuliao_dgv.Rows[i].Cells[7].Value.ToString().Trim()))
                                    {
                                        return false;
                                    }
                                }
                            }
                        }

                    }
                    return true;
                case 3:
                    for (int i = nowsite + 1; i < this.chuku_chanpin_dgv.Rows.Count; i++)
                    {
                        if (this.chuku_chanpin_dgv.Rows[i].Cells[0].Value == null)
                        {
                            continue;
                        }
                        else
                        {

                            if (pinming.Equals(this.chuku_chanpin_dgv.Rows[i].Cells[0].Value.ToString().Trim()))
                            {
                                if (this.chuku_chanpin_dgv.Rows[nowsite].Cells[1].Value == null)
                                {
                                    this.chuku_chanpin_dgv.Rows[nowsite].Cells[1].Value = "";
                                }
                                if (this.chuku_chanpin_dgv.Rows[i].Cells[1].Value == null)
                                {
                                    this.chuku_chanpin_dgv.Rows[i].Cells[1].Value = "";
                                }
                                if (this.chuku_chanpin_dgv.Rows[nowsite].Cells[1].Value.ToString().Trim().Equals(this.chuku_chanpin_dgv.Rows[i].Cells[1].Value.ToString().Trim()))
                                {
                                    if (this.chuku_chanpin_dgv.Rows[nowsite].Cells[7].Value == null)
                                    {
                                        this.chuku_chanpin_dgv.Rows[nowsite].Cells[7].Value = "";
                                    }
                                    if (this.chuku_chanpin_dgv.Rows[i].Cells[7].Value == null)
                                    {
                                        this.chuku_chanpin_dgv.Rows[i].Cells[7].Value = "";
                                    }
                                    if (this.chuku_chanpin_dgv.Rows[nowsite].Cells[7].Value.ToString().Trim().Equals(this.chuku_chanpin_dgv.Rows[i].Cells[7].Value.ToString().Trim()))
                                    {
                                        return false;
                                    }
                                }
                            }
                        }

                    }
                    return true;
                default: return true;
            }

        }
        //出库停止编辑状态时
        private void chuku_yuanliao_dgv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            
        }
        //新建表单
        private void chuku_newdata_Click(object sender, EventArgs e)
        {
            switch (chukustyle)
            {
                case 0: chuku_yuancailiao_init(); break;
                case 1: chuku_tiaoweiliao_init(); break;
                case 2: chuku_fuliao_init(); break;
                case 3: chuku_chanpin_init(); break;
                default: break;
            }

        }
        //查询按钮
        private void chuku_bt_select_Click(object sender, EventArgs e)
        {
            dateselect();
        }
        //日期查询
        private void dateselect()
        {
            //条件查询SERVICE层
            switch (chukustyle)
            {
                case 0:
                    Bean.Chukuguanli_yuancailiaoBean bean = new FWMS.Bean.Chukuguanli_yuancailiaoBean();
                    Service.Chukuguanli_yuanliaoService chukuguanli_yuancailiaoService = new FWMS.Service.Chukuguanli_yuanliaoService();
                    bean.Chuku_yanshou = this.chuku_dtp_select.Value.ToString("yyyyMMdd").Trim();
                    bean = chukuguanli_yuancailiaoService.chukuguanli_yuancailiaoServiceSelectContation(bean);
                    if (bean.Selectresult == null)
                    {
                        MessageBox.Show("数据库中无输入的日期出库信息！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        datagridviewadddata(bean);
                    }
                    break;
                case 1:
                    Bean.Chukuguanli_tiaoweiliaoBean tiaoweiliaobean = new FWMS.Bean.Chukuguanli_tiaoweiliaoBean();
                    Service.Chukuguanli_tiaoweiliaoService tiaoweiliaoService = new FWMS.Service.Chukuguanli_tiaoweiliaoService();
                    tiaoweiliaobean.Chuku_yanshou = this.chuku_dtp_select.Value.ToString("yyyyMMdd").Trim();
                    tiaoweiliaobean = tiaoweiliaoService.chukuguanli_tiaoweiliaoServiceSelectContation(tiaoweiliaobean);
                    if (tiaoweiliaobean.Selectresult == null)
                    {
                        MessageBox.Show("数据库中无输入的日期出库信息！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        datagridviewadddata(tiaoweiliaobean);
                    }
                    break;
                case 2:
                    Bean.Chukuguanli_fuliaoBean fuliaobean = new FWMS.Bean.Chukuguanli_fuliaoBean();
                    Service.Chukuguanli_fuliaoService fuliaoService = new FWMS.Service.Chukuguanli_fuliaoService();
                    fuliaobean.Chuku_yanshou = this.chuku_dtp_select.Value.ToString("yyyyMMdd").Trim();
                    fuliaobean = fuliaoService.chukuguanli_fuliaoServiceSelectContation(fuliaobean);
                    if (fuliaobean.Selectresult == null)
                    {
                        MessageBox.Show("数据库中无输入的日期出库信息！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        datagridviewadddata(fuliaobean);
                    }
                    break;
                case 3:
                    Bean.Chukuguanli_chanpinBean chanpinbean = new FWMS.Bean.Chukuguanli_chanpinBean();
                    Service.Chukuguanli_chanpinService chanpinService = new FWMS.Service.Chukuguanli_chanpinService();
                    chanpinbean.Chuku_yanshou = this.chuku_dtp_select.Value.ToString("yyyyMMdd").Trim();
                    chanpinbean = chanpinService.chukuguanli_chanpinServiceSelectContation(chanpinbean);
                    if (chanpinbean.Selectresult == null)
                    {
                        MessageBox.Show("数据库中无输入的日期出库信息！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        datagridviewadddata(chanpinbean);
                    }
                    break;
                default: break;
            }
        }
        //接收数据并显示
        private void datagridviewadddata(object bean)
        {
            switch (chukustyle)
            {
                case 0:
                    Bean.Chukuguanli_yuancailiaoBean yuancailiaobean = (Bean.Chukuguanli_yuancailiaoBean)bean;
                    string data = yuancailiaobean.Selectresult[0, 0].ToString().Substring(0, 4) + "年" +
                           yuancailiaobean.Selectresult[0, 0].ToString().Substring(4, 2) + "月" +
                           yuancailiaobean.Selectresult[0, 0].ToString().Substring(6, 2) + "日";
                    //验收日期
                    this.chuku_yuanliao_dtp_yanshou.Text = data.Trim();
                    //清除数据集
                    this.chuku_yuanliao_dgv.Rows.Clear();
                    for (int j = 0; j < yuancailiaobean.Resultrow; j++)
                    {
                        this.chuku_yuanliao_dgv.Rows.Add();
                        this.chuku_yuanliao_dgv.Rows[j].Cells[0].Value = COMMAND.Command.toString(yuancailiaobean.Selectresult[j, 1]);
                        this.chuku_yuanliao_dgv.Rows[j].Cells[1].Value = COMMAND.Command.toString(yuancailiaobean.Selectresult[j, 2]);
                        this.chuku_yuanliao_dgv.Rows[j].Cells[2].Value = COMMAND.Command.nulltozero(yuancailiaobean.Selectresult[j, 3]);
                        this.chuku_yuanliao_dgv.Rows[j].Cells[3].Value = COMMAND.Command.nulltozero(yuancailiaobean.Selectresult[j, 4]);
                        this.chuku_yuanliao_dgv.Rows[j].Cells[4].Value = COMMAND.Command.nulltozero(yuancailiaobean.Selectresult[j, 5]);
                        this.chuku_yuanliao_dgv.Rows[j].Cells[5].Value = COMMAND.Command.toString(yuancailiaobean.Selectresult[j, 6]);
                        this.chuku_yuanliao_dgv.Rows[j].Cells[7].Value = COMMAND.Command.toString(yuancailiaobean.Selectresult[j, 7]);
                    }
                    break;
                case 1:

                    Bean.Chukuguanli_tiaoweiliaoBean tiaoweiliaobean = (Bean.Chukuguanli_tiaoweiliaoBean)bean;

                    data = tiaoweiliaobean.Selectresult[0, 0].ToString().Substring(0, 4) + "年" +
                            tiaoweiliaobean.Selectresult[0, 0].ToString().Substring(4, 2) + "月" +
                            tiaoweiliaobean.Selectresult[0, 0].ToString().Substring(6, 2) + "日";
                    //验收日期
                    this.chuku_tiaoweiliao_dtp_yanshou.Text = data;
                    //清除数据集
                    this.chuku_tiaoweiliao_dgv.Rows.Clear();
                    for (int j = 0; j < tiaoweiliaobean.Resultrow; j++)
                    {
                        this.chuku_tiaoweiliao_dgv.Rows.Add();
                        this.chuku_tiaoweiliao_dgv.Rows[j].Cells[0].Value = COMMAND.Command.toString(tiaoweiliaobean.Selectresult[j, 1]);
                        this.chuku_tiaoweiliao_dgv.Rows[j].Cells[1].Value = COMMAND.Command.toString(tiaoweiliaobean.Selectresult[j, 2]);
                        this.chuku_tiaoweiliao_dgv.Rows[j].Cells[2].Value = COMMAND.Command.nulltozero(tiaoweiliaobean.Selectresult[j, 3]);
                        this.chuku_tiaoweiliao_dgv.Rows[j].Cells[3].Value = COMMAND.Command.nulltozero(tiaoweiliaobean.Selectresult[j, 4]);
                        this.chuku_tiaoweiliao_dgv.Rows[j].Cells[4].Value = COMMAND.Command.nulltozero(tiaoweiliaobean.Selectresult[j, 5]);
                        this.chuku_tiaoweiliao_dgv.Rows[j].Cells[5].Value = COMMAND.Command.toString(tiaoweiliaobean.Selectresult[j, 6]);
                        this.chuku_tiaoweiliao_dgv.Rows[j].Cells[7].Value = COMMAND.Command.toString(tiaoweiliaobean.Selectresult[j, 7]);
                    }
                    break;
                case 2:
                    Bean.Chukuguanli_fuliaoBean fuliaobean = (Bean.Chukuguanli_fuliaoBean)bean;
                    data = fuliaobean.Selectresult[0, 0].ToString().Substring(0, 4) + "年" +
                           fuliaobean.Selectresult[0, 0].ToString().Substring(4, 2) + "月" +
                           fuliaobean.Selectresult[0, 0].ToString().Substring(6, 2) + "日";
                    //验收日期
                    this.chuku_fuliao_dtp_yanshou.Text = data;
                    //清除数据集
                    this.chuku_fuliao_dgv.Rows.Clear();
                    for (int j = 0; j < fuliaobean.Resultrow; j++)
                    {
                        this.chuku_fuliao_dgv.Rows.Add();
                        this.chuku_fuliao_dgv.Rows[j].Cells[0].Value = COMMAND.Command.toString(fuliaobean.Selectresult[j, 1]);
                        this.chuku_fuliao_dgv.Rows[j].Cells[1].Value = COMMAND.Command.toString(fuliaobean.Selectresult[j, 2]);
                        this.chuku_fuliao_dgv.Rows[j].Cells[2].Value = COMMAND.Command.nulltozero(fuliaobean.Selectresult[j, 3]);
                        this.chuku_fuliao_dgv.Rows[j].Cells[3].Value = COMMAND.Command.nulltozero(fuliaobean.Selectresult[j, 4]);
                        this.chuku_fuliao_dgv.Rows[j].Cells[4].Value = COMMAND.Command.nulltozero(fuliaobean.Selectresult[j, 5]);
                        this.chuku_fuliao_dgv.Rows[j].Cells[5].Value = COMMAND.Command.toString(fuliaobean.Selectresult[j, 6]);
                        this.chuku_fuliao_dgv.Rows[j].Cells[7].Value = COMMAND.Command.toString(fuliaobean.Selectresult[j, 7]);
                    }
                    break;
                case 3:
                    Bean.Chukuguanli_chanpinBean chanpinbean = (Bean.Chukuguanli_chanpinBean)bean;
                    data = chanpinbean.Selectresult[0, 0].ToString().Substring(0, 4) + "年" +
                           chanpinbean.Selectresult[0, 0].ToString().Substring(4, 2) + "月" +
                           chanpinbean.Selectresult[0, 0].ToString().Substring(6, 2) + "日";
                    //验收日期
                    this.chuku_chanpin_dtp_yanshou.Text = data;
                    //清除数据集
                    this.chuku_chanpin_dgv.Rows.Clear();
                    for (int j = 0; j < chanpinbean.Resultrow; j++)
                    {
                        this.chuku_chanpin_dgv.Rows.Add();
                        this.chuku_chanpin_dgv.Rows[j].Cells[0].Value = COMMAND.Command.toString(chanpinbean.Selectresult[j, 1]);
                        this.chuku_chanpin_dgv.Rows[j].Cells[1].Value = COMMAND.Command.toString(chanpinbean.Selectresult[j, 2]);
                        this.chuku_chanpin_dgv.Rows[j].Cells[2].Value = COMMAND.Command.nulltozero(chanpinbean.Selectresult[j, 3]);
                        this.chuku_chanpin_dgv.Rows[j].Cells[3].Value = COMMAND.Command.nulltozero(chanpinbean.Selectresult[j, 4]);
                        this.chuku_chanpin_dgv.Rows[j].Cells[4].Value = COMMAND.Command.nulltozero(chanpinbean.Selectresult[j, 5]);
                        this.chuku_chanpin_dgv.Rows[j].Cells[5].Value = COMMAND.Command.toString(chanpinbean.Selectresult[j, 6]);
                        this.chuku_chanpin_dgv.Rows[j].Cells[7].Value = COMMAND.Command.toString(chanpinbean.Selectresult[j, 7]);
                    }
                    break;
                default: break;
            }
        }

        private void tsb_select_Click(object sender, EventArgs e)
        {
            dateselect();
        }

        private void btn_addForm_Click(object sender, EventArgs e)
        {
            switch (chukustyle)
            {
                case 0: chuku_yuancailiao_init(); break;
                case 1: chuku_tiaoweiliao_init(); break;
                case 2: chuku_fuliao_init(); break;
                case 3: chuku_chanpin_init(); break;
                default: break;
            }
        }

        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            try
            {
                Clipboard.SetDataObject(this.chuku_yuanliao_dgv.GetClipboardContent());
            }
            catch (Exception)
            {

            }
        }

        private void toolStripMenuItem7_Click(object sender, EventArgs e)
        {
            //从当前单元格的行开始向下粘贴
            if (this.chuku_yuanliao_dgv.CurrentCell == null)
                return;
            int insertRowIndex = this.chuku_yuanliao_dgv.CurrentCell.RowIndex;

            //取得剪贴板的内容，以行分割
            string pasteText = Clipboard.GetText();
            if (string.IsNullOrEmpty(pasteText))
                return;
            pasteText = pasteText.Replace("\r\n", "\n");
            pasteText = pasteText.Replace('\r', '\n');
            pasteText.TrimEnd(new char[] { '\n' });
            string[] lines = pasteText.Split('\n');

            DataGridViewSelectedCellCollection selectedCells = this.chuku_yuanliao_dgv.SelectedCells;
            // 当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.chuku_yuanliao_dgv.SelectedRows;
            foreach (string line in lines)
            {

                try
                {
                    //使用Tab分割
                    string[] vals = line.Split('\t');

                    // if (vals.Length - 1 != this.dataGridView_ruku_tiaoweiliao.ColumnCount)
                    //     throw new ApplicationException("列数不对。");
                    DataGridViewRow row = this.chuku_yuanliao_dgv.Rows[insertRowIndex];

                    //判断要粘贴的剩余行是否够粘贴用 开始....
                    List<int> ss = new List<int>();
                    List<int> coloList = new List<int>();
                    int selectCellRowNum = 1;
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        ss.Add(selectedCells[i].RowIndex);
                        coloList.Add(selectedCells[i].ColumnIndex);
                    }

                    coloList.Sort();
                    ss.Sort();
                    for (int i = 0; i < ss.Count; i++)
                    {

                        if (i + 1 < ss.Count && ss[i] != ss[i + 1])
                        {
                            selectCellRowNum++;
                        }

                    }

                    int j = coloList[0];
                    //设定每个单元格的值
                    for (int m = 0; m < vals.Length; m++)
                    {
                        if (this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[j].GetType().ToString().Equals("System.Windows.Forms.DataGridViewComboBoxCell"))
                        {
                            if (!this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[j].Value.Equals(""))
                            {
                                MessageBox.Show("品名不能粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            continue;

                        }
                        this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[j].Value = vals[m];
                        j++;
                    }

                    Boolean isNum = true;
                    try
                    {
                        //检验单重是否为数字
                        if (this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[3].Value != null && !"".Equals(this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[3].Value.ToString().Trim()))
                        {
                            float.Parse(this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[3].Value.ToString());
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("单价只能为数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[3].Value = null;
                        isNum = false;
                    }

                    try
                    {
                        //检验件数是否为数字
                        if (this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[4].Value != null && !"".Equals(this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[4].Value.ToString().Trim()))
                        {
                            Convert.ToInt32(this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[4].Value);
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("件数只能为整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[4].Value = null;
                        isNum = false;
                    }

                    if (isNum == false)
                    {
                        this.chuku_yuanliao_dgv.Rows[insertRowIndex].Cells[5].Value = null;
                        return;
                    }


                    //向下一行
                    insertRowIndex++;


                }
                catch (Exception)
                {
                    // MessageBox.Show("剩余行数不够，请添加新行以便粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            try
            {
                Clipboard.SetDataObject(this.chuku_tiaoweiliao_dgv.GetClipboardContent());
            }
            catch (Exception)
            {

            }
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            //从当前单元格的行开始向下粘贴
            if (this.chuku_tiaoweiliao_dgv.CurrentCell == null)
                return;
            int insertRowIndex = this.chuku_tiaoweiliao_dgv.CurrentCell.RowIndex;

            //取得剪贴板的内容，以行分割
            string pasteText = Clipboard.GetText();
            if (string.IsNullOrEmpty(pasteText))
                return;
            pasteText = pasteText.Replace("\r\n", "\n");
            pasteText = pasteText.Replace('\r', '\n');
            pasteText.TrimEnd(new char[] { '\n' });
            string[] lines = pasteText.Split('\n');

            DataGridViewSelectedCellCollection selectedCells = this.chuku_tiaoweiliao_dgv.SelectedCells;
            // 当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.chuku_tiaoweiliao_dgv.SelectedRows;
            foreach (string line in lines)
            {

                try
                {
                    //使用Tab分割
                    string[] vals = line.Split('\t');

                    // if (vals.Length - 1 != this.dataGridView_ruku_tiaoweiliao.ColumnCount)
                    //     throw new ApplicationException("列数不对。");
                    DataGridViewRow row = this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex];

                    //判断要粘贴的剩余行是否够粘贴用 开始....
                    List<int> ss = new List<int>();
                    List<int> coloList = new List<int>();
                    int selectCellRowNum = 1;
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        ss.Add(selectedCells[i].RowIndex);
                        coloList.Add(selectedCells[i].ColumnIndex);
                    }

                    coloList.Sort();
                    ss.Sort();
                    for (int i = 0; i < ss.Count; i++)
                    {

                        if (i + 1 < ss.Count && ss[i] != ss[i + 1])
                        {
                            selectCellRowNum++;
                        }

                    }

                    int j = coloList[0];
                    //设定每个单元格的值
                    for (int m = 0; m < vals.Length; m++)
                    {
                        if (this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[j].GetType().ToString().Equals("System.Windows.Forms.DataGridViewComboBoxCell"))
                        {
                            if (!this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[j].Value.Equals(""))
                            {
                                MessageBox.Show("品名不能粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            continue;

                        }
                        this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[j].Value = vals[m];
                        j++;
                    }

                    Boolean isNum = true;
                    try
                    {
                        //检验单重是否为数字
                        if (this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[3].Value != null && !"".Equals(this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[3].Value.ToString().Trim()))
                        {
                            float.Parse(this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[3].Value.ToString());
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("单价只能为数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[3].Value = null;
                        isNum = false;
                    }

                    try
                    {
                        //检验件数是否为数字
                        if (this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[4].Value != null && !"".Equals(this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[4].Value.ToString().Trim()))
                        {
                            Convert.ToInt32(this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[4].Value);
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("件数只能为整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[4].Value = null;
                        isNum = false;
                    }

                    if (isNum == false)
                    {
                        this.chuku_tiaoweiliao_dgv.Rows[insertRowIndex].Cells[5].Value = null;
                        return;
                    }


                    //向下一行
                    insertRowIndex++;


                }
                catch (Exception)
                {
                    // MessageBox.Show("剩余行数不够，请添加新行以便粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            try
            {
                Clipboard.SetDataObject(this.chuku_fuliao_dgv.GetClipboardContent());
            }
            catch (Exception)
            {

            }
        }

        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            //从当前单元格的行开始向下粘贴
            if (this.chuku_fuliao_dgv.CurrentCell == null)
                return;
            int insertRowIndex = this.chuku_fuliao_dgv.CurrentCell.RowIndex;

            //取得剪贴板的内容，以行分割
            string pasteText = Clipboard.GetText();
            if (string.IsNullOrEmpty(pasteText))
                return;
            pasteText = pasteText.Replace("\r\n", "\n");
            pasteText = pasteText.Replace('\r', '\n');
            pasteText.TrimEnd(new char[] { '\n' });
            string[] lines = pasteText.Split('\n');

            DataGridViewSelectedCellCollection selectedCells = this.chuku_fuliao_dgv.SelectedCells;
            // 当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.chuku_fuliao_dgv.SelectedRows;
            foreach (string line in lines)
            {

                try
                {
                    //使用Tab分割
                    string[] vals = line.Split('\t');

                    // if (vals.Length - 1 != this.dataGridView_ruku_tiaoweiliao.ColumnCount)
                    //     throw new ApplicationException("列数不对。");
                    DataGridViewRow row = this.chuku_fuliao_dgv.Rows[insertRowIndex];

                    //判断要粘贴的剩余行是否够粘贴用 开始....
                    List<int> ss = new List<int>();
                    List<int> coloList = new List<int>();
                    int selectCellRowNum = 1;
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        ss.Add(selectedCells[i].RowIndex);
                        coloList.Add(selectedCells[i].ColumnIndex);
                    }

                    coloList.Sort();
                    ss.Sort();
                    for (int i = 0; i < ss.Count; i++)
                    {

                        if (i + 1 < ss.Count && ss[i] != ss[i + 1])
                        {
                            selectCellRowNum++;
                        }

                    }

                    int j = coloList[0];
                    //设定每个单元格的值
                    for (int m = 0; m < vals.Length; m++)
                    {
                        if (this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[j].GetType().ToString().Equals("System.Windows.Forms.DataGridViewComboBoxCell"))
                        {
                            if (!this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[j].Value.Equals(""))
                            {
                                MessageBox.Show("品名不能粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            continue;

                        }
                        this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[j].Value = vals[m];
                        j++;
                    }

                    Boolean isNum = true;
                    try
                    {
                        //检验单重是否为数字
                        if (this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[3].Value != null && !"".Equals(this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[3].Value.ToString().Trim()))
                        {
                            float.Parse(this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[3].Value.ToString());
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("单价只能为数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[3].Value = null;
                        isNum = false;
                    }

                    try
                    {
                        //检验件数是否为数字
                        if (this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[4].Value != null && !"".Equals(this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[4].Value.ToString().Trim()))
                        {
                            Convert.ToInt32(this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[4].Value);
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("件数只能为整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[4].Value = null;
                        isNum = false;
                    }

                    if (isNum == false)
                    {
                        this.chuku_fuliao_dgv.Rows[insertRowIndex].Cells[5].Value = null;
                        return;
                    }


                    //向下一行
                    insertRowIndex++;


                }
                catch (Exception)
                {
                    // MessageBox.Show("剩余行数不够，请添加新行以便粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }

        private void toolStripMenuItem5_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            try
            {
                Clipboard.SetDataObject(this.chuku_chanpin_dgv.GetClipboardContent());
            }
            catch (Exception)
            {

            }

        }

        private void toolStripMenuItem8_Click(object sender, EventArgs e)
        {
            //从当前单元格的行开始向下粘贴
            if (this.chuku_chanpin_dgv.CurrentCell == null)
                return;
            int insertRowIndex = this.chuku_chanpin_dgv.CurrentCell.RowIndex;

            //取得剪贴板的内容，以行分割
            string pasteText = Clipboard.GetText();
            if (string.IsNullOrEmpty(pasteText))
                return;
            pasteText = pasteText.Replace("\r\n", "\n");
            pasteText = pasteText.Replace('\r', '\n');
            pasteText.TrimEnd(new char[] { '\n' });
            string[] lines = pasteText.Split('\n');

            DataGridViewSelectedCellCollection selectedCells = this.chuku_chanpin_dgv.SelectedCells;
            // 当前选中行
            DataGridViewSelectedRowCollection selectedRows = this.chuku_chanpin_dgv.SelectedRows;
            foreach (string line in lines)
            {

                try
                {
                    //使用Tab分割
                    string[] vals = line.Split('\t');

                    // if (vals.Length - 1 != this.dataGridView_ruku_tiaoweiliao.ColumnCount)
                    //     throw new ApplicationException("列数不对。");
                    DataGridViewRow row = this.chuku_chanpin_dgv.Rows[insertRowIndex];

                    //判断要粘贴的剩余行是否够粘贴用 开始....
                    List<int> ss = new List<int>();
                    List<int> coloList = new List<int>();
                    int selectCellRowNum = 1;
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        ss.Add(selectedCells[i].RowIndex);
                        coloList.Add(selectedCells[i].ColumnIndex);
                    }

                    coloList.Sort();
                    ss.Sort();
                    for (int i = 0; i < ss.Count; i++)
                    {

                        if (i + 1 < ss.Count && ss[i] != ss[i + 1])
                        {
                            selectCellRowNum++;
                        }

                    }

                    int j = coloList[0];
                    //设定每个单元格的值
                    for (int m = 0; m < vals.Length; m++)
                    {
                        if (this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[j].GetType().ToString().Equals("System.Windows.Forms.DataGridViewComboBoxCell"))
                        {
                            if (!this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[j].Value.Equals(""))
                            {
                                MessageBox.Show("品名不能粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            continue;

                        }
                        this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[j].Value = vals[m];
                        j++;
                    }

                    Boolean isNum = true;
                    try
                    {
                        //检验单重是否为数字
                        if (this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[3].Value != null && !"".Equals(this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[3].Value.ToString().Trim()))
                        {
                            float.Parse(this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[3].Value.ToString());
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("单价只能为数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[3].Value = null;
                        isNum = false;
                    }

                    try
                    {
                        //检验件数是否为数字
                        if (this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[4].Value != null && !"".Equals(this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[4].Value.ToString().Trim()))
                        {
                            Convert.ToInt32(this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[4].Value);
                        }

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("件数只能为整数！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[4].Value = null;
                        isNum = false;
                    }

                    if (isNum == false)
                    {
                        this.chuku_chanpin_dgv.Rows[insertRowIndex].Cells[5].Value = null;
                        return;
                    }


                    //向下一行
                    insertRowIndex++;


                }
                catch (Exception)
                {
                    // MessageBox.Show("剩余行数不够，请添加新行以便粘贴！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }
        //当前出库时间和库存保存时间进行比较
        private bool comsavedate(string date, string type)
        {
            Service.Rukuguanli_yuancailiaoService service = new FWMS.Service.Rukuguanli_yuancailiaoService();
            string maxdate = service.rukuguanli_getkucunmaxdate(type);
            if (maxdate == null || "".Equals(maxdate))
            {
                return true;
            }
            else
            {
                if (int.Parse(date) <= int.Parse(maxdate))
                {
                    MessageBox.Show("当前验收日期已经集计结束，不能在当前验收日期或之前进行出库操作", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }

        private void chuku_yuanliao_dgv_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.chuku_yuanliao_dgv.CurrentCell.ColumnIndex == 3)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.chuku_yuanliao_dgv.CurrentCell.ColumnIndex == 4)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.chuku_yuanliao_dgv.CurrentCell.ColumnIndex == 5)
            {

                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
        }

        private void chuku_yuanliao_dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.chuku_yuanliao_dgv.CurrentCell.ColumnIndex == 3 || this.chuku_yuanliao_dgv.CurrentCell.ColumnIndex == 4 || this.chuku_yuanliao_dgv.CurrentCell.ColumnIndex == 5)
            {
                Control cotrol = (Control)e.Control;
                cotrol.KeyPress += new KeyPressEventHandler(chuku_yuanliao_dgv_KeyPress);
            }
        }

        private void chuku_tiaoweiliao_dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.chuku_tiaoweiliao_dgv.CurrentCell.ColumnIndex == 3 || this.chuku_tiaoweiliao_dgv.CurrentCell.ColumnIndex == 4 || this.chuku_tiaoweiliao_dgv.CurrentCell.ColumnIndex == 5)
            {
                Control cotrol = (Control)e.Control;
                cotrol.KeyPress += new KeyPressEventHandler(chuku_tiaoweiliao_dgv_KeyPress);
            }
        }

        private void chuku_tiaoweiliao_dgv_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.chuku_tiaoweiliao_dgv.CurrentCell.ColumnIndex == 3)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.chuku_tiaoweiliao_dgv.CurrentCell.ColumnIndex == 4)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.chuku_tiaoweiliao_dgv.CurrentCell.ColumnIndex == 5)
            {

                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
        }

        private void chuku_fuliao_dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.chuku_fuliao_dgv.CurrentCell.ColumnIndex == 3 || this.chuku_fuliao_dgv.CurrentCell.ColumnIndex == 4 || this.chuku_fuliao_dgv.CurrentCell.ColumnIndex == 5)
            {
                Control cotrol = (Control)e.Control;
                cotrol.KeyPress += new KeyPressEventHandler(chuku_fuliao_dgv_KeyPress);
            }
        }

        private void chuku_fuliao_dgv_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.chuku_fuliao_dgv.CurrentCell.ColumnIndex == 3)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.chuku_fuliao_dgv.CurrentCell.ColumnIndex == 4)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.chuku_fuliao_dgv.CurrentCell.ColumnIndex == 5)
            {

                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
        }

        private void chuku_chanpin_dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.chuku_chanpin_dgv.CurrentCell.ColumnIndex == 3 || this.chuku_chanpin_dgv.CurrentCell.ColumnIndex == 4 || this.chuku_chanpin_dgv.CurrentCell.ColumnIndex == 5)
            {
                Control cotrol = (Control)e.Control;
                cotrol.KeyPress += new KeyPressEventHandler(chuku_chanpin_dgv_KeyPress);
            }
        }

        private void chuku_chanpin_dgv_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.chuku_chanpin_dgv.CurrentCell.ColumnIndex == 3)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.chuku_chanpin_dgv.CurrentCell.ColumnIndex == 4)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
            if (this.chuku_chanpin_dgv.CurrentCell.ColumnIndex == 5)
            {
                if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 46) && (e.KeyChar != 8) && (e.KeyChar != 13) && e.KeyChar != 45)
                    e.Handled = true;
                else
                    e.Handled = false;
            }
        }

        private void tiaoliao_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection selectecCells = this.chuku_tiaoweiliao_dgv.SelectedCells;

            foreach (DataGridViewCell cell in selectecCells)
            {
                
                cell.Value = null;
            }
        }

        private void yuanliao_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection selectecCells = this.chuku_yuanliao_dgv.SelectedCells;

            foreach (DataGridViewCell cell in selectecCells)
            {
                cell.Value = null;
            }
        }

        private void fuliao_DelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection selectecCells = this.chuku_fuliao_dgv.SelectedCells;

            foreach (DataGridViewCell cell in selectecCells)
            {
                cell.Value = null;
            }
        }

        private void chengpin_DelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection selectecCells = this.chuku_chanpin_dgv.SelectedCells;

            foreach (DataGridViewCell cell in selectecCells)
            {
                cell.Value = null;
            }
        }

        //原料导出EXCEL按钮按下
        private void chanpin_importexcel()
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            string path2 = "";
            saveFileDialog1.Filter = "EXCEL files(*.xls)|*.xls";
            saveFileDialog1.FilterIndex = 1;
            saveFileDialog1.RestoreDirectory = true;
            //保存EXCEL
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                path2 = saveFileDialog1.FileName.ToString();
            }
            else
            {
                return;
            }
            saveFileDialog1.Dispose();

            string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            if (File.Exists(path2))
            {
                IntPtr vHandle = _lopen(path2, OF_READWRITE | OF_SHARE_DENY_NONE);
                if (vHandle == HFILE_ERROR)
                {
                    MessageBox.Show("该文件已经打开，请关闭后重新导出！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    CloseHandle(vHandle);
                    File.Delete(path2);
                }
            }
            COMMAND.CommandMicrosoftExcel importexcel = new FWMS.COMMAND.CommandMicrosoftExcel();
            importexcel.Open(path + "\\成品出库明细MODEL.xls");
            int k = 0;
            //数据集合导出
            for (int i = 0; i < this.chuku_chanpin_dgv.Rows.Count - 1; i++)
            {
                if (!"".Equals(COMMAND.Command.toString(this.chuku_chanpin_dgv.Rows[i].Cells[0].Value).Trim()))
                {
                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 1, this.chuku_chanpin_dgv.Rows[i].Cells[0].Value.ToString().Trim());
                    k++;

                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 2, COMMAND.Command.toString(this.chuku_chanpin_dgv.Rows[i].Cells[1].Value));

                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 3, COMMAND.Command.toString(this.chuku_chanpin_dgv.Rows[i].Cells[2].Value));

                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 4, COMMAND.Command.toString(this.chuku_chanpin_dgv.Rows[i].Cells[3].Value));

                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 5, COMMAND.Command.toString(this.chuku_chanpin_dgv.Rows[i].Cells[4].Value));

                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 6, COMMAND.Command.toString(this.chuku_chanpin_dgv.Rows[i].Cells[5].Value));

                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 7, COMMAND.Command.toString(this.chuku_chanpin_dgv.Rows[i].Cells[5].Value));

                    importexcel.SetCellValue(importexcel.GetSheet(sheet4name), 5 + i, 8, COMMAND.Command.toString(this.chuku_chanpin_dgv.Rows[i].Cells[7].Value));

                }
                else
                {
                    continue;
                }

            }
            if (k == 0)
            {
                MessageBox.Show("当前无数据,请输入数据再导出！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (k < 21)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("成品出库明细1"), 27, 53);
            }
            else if (k > 40 && k < 61)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("成品出库明细2"), 27, 53);
            }
            else if (k > 80 && k < 101)
            {
                importexcel.setRowsHidden(importexcel.GetSheet("成品出库明细3"), 27, 53);
            }
            importexcel.SaveAs(path2);
            importexcel.Close();
            MessageBox.Show("导出EXCEL成功，请注意保存当前数据！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void chanpin_importexcel_btn_Click_1(object sender, EventArgs e)
        {
            chanpin_importexcel();
        }

        private void chuku_yuanliao_dgv_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            lbl_sum.Visible = true;
            double sum = 0;
            bool isVisible = true;
            foreach (DataGridViewCell cell in this.chuku_yuanliao_dgv.SelectedCells)
            {
                if (cell.Value != null)
                {
                    if (COMMAND.Command.IsFloat(cell.Value.ToString()))
                    {
                        sum += Math.Round(float.Parse(cell.Value.ToString()), 3);
                    }
                    else
                    {
                        isVisible = false;
                    }
                }
                else
                {
                    isVisible = false;
                }
            }
            lbl_sum.Text = "求和=" + Convert.ToString(sum);
            if (!isVisible)
            {
                lbl_sum.Visible = false;
            }
        }

        private void chuku_tiaoweiliao_dgv_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            lbl_sum.Visible = true;
            double sum = 0;
            bool isVisible = true;
            foreach (DataGridViewCell cell in this.chuku_tiaoweiliao_dgv.SelectedCells)
            {
                if (cell.Value != null)
                {
                    if (COMMAND.Command.IsFloat(cell.Value.ToString()))
                    {
                        sum += Math.Round(float.Parse(cell.Value.ToString()), 3);
                    }
                    else
                    {
                        isVisible = false;
                    }
                }
                else
                {
                    isVisible = false;
                }
            }
            lbl_sum.Text = "求和=" + Convert.ToString(sum);
            if (!isVisible)
            {
                lbl_sum.Visible = false;
            }
        }

        private void chuku_fuliao_dgv_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            lbl_sum.Visible = true;
            double sum = 0;
            bool isVisible = true;
            foreach (DataGridViewCell cell in this.chuku_fuliao_dgv.SelectedCells)
            {
                if (cell.Value != null)
                {
                    if (COMMAND.Command.IsFloat(cell.Value.ToString()))
                    {
                        sum += Math.Round(float.Parse(cell.Value.ToString()), 3);
                    }
                    else
                    {
                        isVisible = false;
                    }
                }
                else
                {
                    isVisible = false;
                }
            }
            lbl_sum.Text = "求和=" + Convert.ToString(sum);
            if (!isVisible)
            {
                lbl_sum.Visible = false;
            }
        }

        private void chuku_chanpin_dgv_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            lbl_sum.Visible = true;
            double sum = 0;
            bool isVisible = true;
            foreach (DataGridViewCell cell in this.chuku_chanpin_dgv.SelectedCells)
            {
                if (cell.Value != null)
                {
                    if (COMMAND.Command.IsFloat(cell.Value.ToString()))
                    {
                        sum += Math.Round(float.Parse(cell.Value.ToString()), 3);
                    }
                    else
                    {
                        isVisible = false;
                    }
                }
                else
                {
                    isVisible = false;
                }
            }
            lbl_sum.Text = "求和=" + Convert.ToString(sum);
            if (!isVisible)
            {
                lbl_sum.Visible = false;
            }
        }

    }
}
